package com.taobao.schedule.utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.net.URL;
import java.util.List;

import org.apache.log4j.Logger;

public class TextUtil {

	private static Logger log = Logger.getLogger(TextUtil.class);
	public static String fileName = "shell.txt";

	public static String getCurrentShell() {
		StringBuffer sb = new StringBuffer();
		try {
			BufferedReader br = new BufferedReader(new FileReader(fileName));
			String line = null;
			while (br != null && (line = br.readLine()) != null) {
				sb.append(line);
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String result = sb.toString();
		log.warn("当前执行的shell=" + result);
		return result;
	}

	public static String list2String(List<? extends Object> list) {
		if (list == null) {
			return null;
		}
		StringBuilder sb = new StringBuilder();
		for (Object obj : list) {
			sb.append(obj.toString()).append(",");
		}
		if (sb.length() > 0) {
			sb.deleteCharAt(sb.length() - 1);
		}
		return sb.toString();
	}

	public static void setFileName(String name){
		fileName = name;
	}
	
	public static void main(String[] args) {
		System.out.println("---------"+getCurrentShell());
//		URL u = TextUtil.class.getResource("../../../../");
//		File f = new File("./");
//		if(f.isDirectory()){
//			String[] files = f.list();
//			for(String ff : files){
//				System.out.println(ff);
//			}
//		}
//		System.out.println(u.toString());
	}
	
}
